package com.pureut.production.controller;


import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.production.domain.dto.SpunlaceOutputDto;
import com.pureut.production.domain.vo.SpunlaceOutputVo;
import com.pureut.production.domain.vo.SpunlacePrintVo;
import com.pureut.production.domain.vo.SpunlaceWasteVo;
import com.pureut.production.domain.vo.StockInVo;
import com.pureut.production.service.SpunlaceOutputService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 水刺产出控制层
 * @author: CM
 * @date: 2023/2/20  17:22
 */
@RestController
@RequestMapping("/spunlaceOutput")
public class SpunlaceOutputController extends BaseController {

    @Resource
    private SpunlaceOutputService spunlaceOutputService;

    /**
     * 新增水刺产出列表
     */
    @Log(title = "新增水刺产出列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody SpunlaceOutputVo spunlaceOutputVo){
        return toAjax(spunlaceOutputService.add(spunlaceOutputVo));
    }

    /**
     * 产出打印回显
     */
    @GetMapping("/view/{id}")
    @RequiresPermissions("productionTube:produAdm:spunlace:spunproduc:out")
    public AjaxResult view(@PathVariable("id") Long id) {
        return AjaxResult.success(spunlaceOutputService.getView(id));
    }

    /**
     * 产出打印
     */
    @Log(title = "产出打印", businessType = BusinessType.INSERT)
    @PostMapping("/addPrint")
    public AjaxResult addPrint(@Validated @RequestBody SpunlacePrintVo spunlacePrintVo) throws Exception {
        return AjaxResult.success(spunlaceOutputService.addPrint(spunlacePrintVo));
    }

    /**
     * 水刺产出列表
     */
    @RequiresPermissions("productionTube:produAdm:spunlace:spunproduc:list")
    @GetMapping("/list")
    public TableDataInfo selectOperationList(SpunlaceOutputVo spunlaceOutputVo) {
        startPage();
        // 查询工序信息列表
        List<SpunlaceOutputDto> list = spunlaceOutputService.getList(spunlaceOutputVo);
        return getDataTable(list);
    }

    /**
     * 扫描入库
     */
    @RequiresPermissions("productionTube:produAdm:spunlace:spunproduc:scan")
    @PostMapping("/stockIn")
    @Log(title = "扫描入库", businessType = BusinessType.INSERT)
    public AjaxResult stockIn(@RequestBody StockInVo stockInVo) throws Exception {
        return AjaxResult.success(spunlaceOutputService.stockIn(stockInVo));
    }


    @RequiresPermissions("productionTube:produAdm:spunlace:spunproduc:wastePrint")
    @Log(title = "废料打印", businessType = BusinessType.INSERT)
    @PostMapping("/wastePrint")
    public AjaxResult wastePrint(@RequestBody SpunlaceWasteVo SpunlaceWasteVo) throws Exception {
        return AjaxResult.success(spunlaceOutputService.wastePrint(SpunlaceWasteVo));
    }

    @RequiresPermissions("productionTube:produAdm:spunlace:spunproduc:billOk")
    @Log(title = "单据完成", businessType = BusinessType.UPDATE)
    @PutMapping("/finish")
    public AjaxResult finish(@RequestBody  SpunlaceOutputVo spunlaceOutputVo){
        return toAjax(spunlaceOutputService.finish(spunlaceOutputVo));
    }

    /**
     * 水刺产出查看
     */
    @RequiresPermissions("productionTube:produAdm:spunlace:spunproduc:query")
    @GetMapping("/getView/{id}")
    public AjaxResult getViewInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(spunlaceOutputService.getViewInfo(id));
    }

    /**
     * 产出统计
     */
    @RequiresPermissions("productionTube:produAdm:spunlace:spunproduc:outStatistics")
    @GetMapping("/outputStatic")
    public AjaxResult outputStatic(String moNumber) {
        return AjaxResult.success(spunlaceOutputService.outputStatic(moNumber));
    }

}
